package lew.bing.exp.java10;

import com.google.common.collect.Lists;
import com.google.common.collect.Streams;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Random;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Created by 刘国兵 on 2018/8/12.
 */
public class TestVar {

    public static void main(String[] args) {
        // stream是懒惰的

        Streams.stream(new Iterator<Object>() {
            int i = 0;
            int j = 1;
            @Override
            public boolean hasNext() {
                return true;
            }

            @Override
            public Object next() {
                System.out.println("生成下一个");
                var k = i;
                i = j;
                j = k + j;
                return k;
            }
        }).limit(10L).forEach(System.out::println);
        final Random random = new Random();
        Streams.stream((GenerateIterator<Object>) () -> random.nextInt(100)).limit(100).forEach(System.out::println);
        Consumer printConsumer = System.out::println;
        Stream stream = Stream.of(1,2,3,4,5);

        stream.forEach(printConsumer);
        String collect = Stream.of(1, 2, 3).map(String::valueOf).collect(Collectors.joining("|", "(", ")"));
        System.out.println(collect);
//        stream.forEach(printConsumer);


    }

}
